package com.fufan.mtsaas.modules.unsafeevent.baqsjrecordmain.service.impl;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fufan.mtsaas.modules.common.bo.response.RequestPojo;
import com.fufan.mtsaas.modules.common.bo.response.ResStatus;
import com.fufan.mtsaas.modules.common.bo.response.Result;
import com.fufan.mtsaas.modules.unsafeevent.baqsjcommon.*;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordaccident.bo.request.*;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordaccident.dao.BaqsjRecordAccidentDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordaccident.model.BaqsjRecordAccident;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordaccidentother.dao.BaqsjRecordAccidentOtherDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordaccidentother.model.BaqsjRecordAccidentOther;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordhandle.dao.BaqsjRecordHandleDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordhandle.model.BaqsjRecordHandle;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordinputblood.dao.BaqsjRecordInputbloodDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordinputblood.model.BaqsjRecordInputblood;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordmain.bo.request.*;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordmain.bo.response.*;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordmain.dao.BaqsjRecordDetailDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordmain.dao.BaqsjRecordMainDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordmain.model.BaqsjRecordDetail;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordmain.model.BaqsjRecordMain;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordmedicalinstrument.dao.BaqsjRecordMedicalinstrumentDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordmedicalinstrument.model.BaqsjRecordMedicalinstrument;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordnegotiation.dao.BaqsjRecordNegotiationDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordnegotiation.model.BaqsjRecordNegotiation;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordoperation.bo.request.BaqsjRecordNonPlaned;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordoperation.bo.request.BaqsjRecordOperationBad;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordoperation.bo.request.BaqsjRecordSurgicalBad;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordoperation.dao.BaqsjRecordOperationDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordother.bo.request.BaqsjRecordOtherPublic;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordother.bo.request.BaqsjRecordOtherPublicSecurity;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordother.dao.BaqsjRecordOtherDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordproperty.dao.BaqsjRecordPropertyDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordproperty.model.BaqsjRecordProperty;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordprotection.dao.BaqsjRecordProtectionDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordprotection.model.BaqsjRecordProtection;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordreport.dao.BaqsjRecordReportDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordreport.model.BaqsjRecordReport;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordtransfusion.dao.BaqsjRecordTransfusionDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordtransfusion.model.BaqsjRecordTransfusion;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecorduntowardeffect.dao.BaqsjRecordUntowardeffectDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecorduntowardeffect.model.BaqsjRecordUntowardeffect;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordwrongblood.dao.BaqsjRecordWrongbloodDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordwrongblood.model.BaqsjRecordWrongblood;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordwrongdrug.dao.BaqsjRecordWrongdrugDao;
import com.fufan.mtsaas.modules.unsafeevent.baqsjrecordwrongdrug.model.BaqsjRecordWrongdrug;
import com.fufan.mtsaas.util.DateUtil;
import com.fufan.mtsaas.util.JSonUtil;
import com.fufan.mtsaas.util.ParamUtil;
import com.fufan.mtsaas.util.SetGetUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.*;

@Service("BaqsjRecordEventProcessSvcImpl")
@Slf4j
@Primary
public class BaqsjRecordEventProcess implements BaqsjRecordBaseProcess {
    @Autowired
    private ParamUtil paramUtil;
    @Autowired
    private BaqsjRecordMainDao baqsjRecordMainDao;
    @Autowired
    private BaqsjRecordDetailDao baqsjRecordDetailDao;
    @Autowired
    private BaqsjRecordPropertyDao baqsjRecordPropertyDao;
    @Autowired
    private BaqsjRecordReportDao baqsjRecordReportDao;
    @Autowired
    private BaqsjRecordHandleDao baqsjRecordHandleDao;
    @Autowired
    private BaqsjRecordAccidentDao baqsjRecordAccidentDao;
    @Autowired
    private BaqsjRecordAccidentOtherDao baqsjRecordAccidentOtherDao;
    @Autowired
    private BaqsjRecordInputbloodDao baqsjRecordInputbloodDao;
    @Autowired
    private BaqsjRecordMedicalinstrumentDao baqsjRecordMedicalinstrumentDao;
    @Autowired
    private BaqsjRecordNegotiationDao baqsjRecordNegotiationDao;
    @Autowired
    private BaqsjRecordOperationDao baqsjRecordOperationDao;
    @Autowired
    private BaqsjRecordOtherDao baqsjRecordOtherDao;
    @Autowired
    private BaqsjRecordProtectionDao baqsjRecordProtectionDao;
    @Autowired
    private BaqsjRecordTransfusionDao baqsjRecordTransfusionDao;
    @Autowired
    private BaqsjRecordUntowardeffectDao baqsjRecordUntowardeffectDao;
    @Autowired
    private BaqsjRecordWrongbloodDao baqsjRecordWrongbloodDao;
    @Autowired
    private BaqsjRecordWrongdrugDao baqsjRecordWrongdrugDao;

    private Map<Class<?>, Object> daoMap = new HashMap<>();
    private Map<String, Class<?>> classMap = new HashMap<>();

    public BaqsjRecordEventProcess() {

        classMap = new HashMap<>();
        classMap.put("BaqsjRecordProperty", BaqsjRecordProperty.class);
        classMap.put("BaqsjRecordReport", BaqsjRecordReport.class);
        classMap.put("BaqsjRecordHandle", BaqsjRecordHandle.class);
        classMap.put("BaqsjRecordAccidentChokingFood", BaqsjRecordAccident.class);
        classMap.put("BaqsjRecordAccidentFall", BaqsjRecordAccident.class);
        classMap.put("BaqsjRecordAccidentHurt", BaqsjRecordAccidentHurt.class);
        classMap.put("BaqsjRecordAccidentOther", BaqsjRecordAccidentOther.class);
        classMap.put("BaqsjRecordAccidentOut", BaqsjRecordAccidentOut.class);
        classMap.put("BaqsjRecordAccidentSelfKill", BaqsjRecordAccidentOther.class);
        classMap.put("BaqsjRecordDiagnosisDietWrong", Object.class);
        classMap.put("BaqsjRecordDiagnosisInfusionReaction", Object.class);
        classMap.put("BaqsjRecordDiagnosisMedicalHandle", Object.class);
        classMap.put("BaqsjRecordDiagnosisOtherReaction", Object.class);
        classMap.put("BaqsjRecordDiagnosisSampleWrong", Object.class);
        classMap.put("BaqsjRecordDoctorAndPatientNegotiation", BaqsjRecordNegotiation.class);
        classMap.put("BaqsjRecordHospitalInfected", Object.class);
        classMap.put("BaqsjRecordMedicalBadReaction", BaqsjRecordUntowardeffect.class);
        classMap.put("BaqsjRecordMedicalWrongDrug", BaqsjRecordWrongdrug.class);
        classMap.put("BaqsjRecordMedicalInstrument", BaqsjRecordMedicalinstrument.class);
        classMap.put("BaqsjRecordOtherReactionGeneral", Object.class);
        classMap.put("BaqsjRecordOtherReactionPublic", BaqsjRecordOtherPublic.class);
        classMap.put("BaqsjRecordOtherReactionPublicSecurity", BaqsjRecordOtherPublicSecurity.class);
        classMap.put("BaqsjRecordPreventionAndProtection", BaqsjRecordProtection.class);
        classMap.put("BaqsjRecordSurgicalBad", BaqsjRecordSurgicalBad.class);
        classMap.put("BaqsjRecordSurgicalNonPlaned", BaqsjRecordNonPlaned.class);
        classMap.put("BaqsjRecordSurgicalOperationBad", BaqsjRecordOperationBad.class);
        classMap.put("BaqsjRecordTransfusionBloodReaction", BaqsjRecordTransfusion.class);
        classMap.put("BaqsjRecordTransfusionWrongBlood", BaqsjRecordWrongblood.class);

    }
    /**
     * @param eventNo
     * @param dataRequest
     * @param requestPojo
     * @return
     */
    @Override
    public Result processEventData(String eventNo, Object dataRequest, RequestPojo requestPojo) {
        Result result = new Result();
        Page page = new Page();

        String eventList = paramUtil.getTSysParam("BAQSJ_EVENT");
        List<EventClassListBo> eventClassListBoList = null;
        ObjectMapper mapper = new ObjectMapper();
        try {
            eventClassListBoList = mapper.readValue(eventList, new TypeReference<List<EventClassListBo>>() {
            });
        } catch (IOException e) {
            e.printStackTrace();
            result.setResStatus(ResStatus.STATUS_FAILED);
            result.setResMsg(ResStatus.STATUS_FAILED_MSG + ":" + e.getLocalizedMessage());
            return result;
        }

        UnsafeeventBaseSaveRequest baseSaveRequest = new UnsafeeventBaseSaveRequest();
        BeanUtils.copyProperties(dataRequest, baseSaveRequest);
        int insertOrUpdate = 0;
        Long sysId = (Long) SetGetUtil.getField(baseSaveRequest, "id");
        if (Objects.nonNull(sysId) && sysId != 0) {
            insertOrUpdate = 1;
        }

        BaqsjRecordMain main = new BaqsjRecordMain();
        Integer auditStatus = (Integer) SetGetUtil.getField(baseSaveRequest, "auditStatus");
        main.setAuditStatus(auditStatus);
        main.setChannel(0);
        main.setEventNo(eventNo);
        String eventName = BaqsjEventCOMMON.getEventName(eventNo);
        main.setEventName(eventName);
        main.setCompanyId(Long.valueOf(requestPojo.getCustId()));
        main.setIsEnabled(0);
        main.setDelFlag(0);
        if (main.getAuditStatus() == 1) {
            main.setStatus(10);
        } else {
            main.setStatus(0);
        }
        main.setCreateBy(String.valueOf(requestPojo.getSysId()));
        main.setCreateTime(DateUtil.parseDate(DateUtil.formatDate(new Date(), DateUtil.DATE_TIME_FORMAT), DateUtil.DATE_TIME_FORMAT));
        main.setUpdateBy(String.valueOf(requestPojo.getSysId()));
        main.setUpdateTime(DateUtil.parseDate(DateUtil.formatDate(new Date(), DateUtil.DATE_TIME_FORMAT), DateUtil.DATE_TIME_FORMAT));
        if (insertOrUpdate == 0) {
            main.setId(0L);
            baqsjRecordMainDao.insert(main);
        } else {
            baqsjRecordMainDao.updateById(main);
        }

        BaqsjRecordDetail detail = new BaqsjRecordDetail();
        detail.setId(0L);
        detail.setEventId(main.getId());
        detail.setEventDetail(JSonUtil.toJSONString(dataRequest));
        baqsjRecordDetailDao.insert(detail);

        SetGetUtil.setField(dataRequest, "id", main.getId());
        SetGetUtil.setField(dataRequest, "auditStatus", main.getAuditStatus());
        SetGetUtil.setField(dataRequest, "eventNo", main.getEventNo());
        SetGetUtil.setField(dataRequest, "eventName", main.getEventName());

        Map<String, Object> dataParts = new HashMap<>();
        dataParts.put("BaqsjRecordProperty", SetGetUtil.getField(dataRequest, "BaqsjRecordProperty"));
        dataParts.put("BaqsjRecordReport", SetGetUtil.getField(dataRequest, "BaqsjRecordReport"));
        dataParts.put("BaqsjRecordHandle", SetGetUtil.getField(dataRequest, "BaqsjRecordHandle"));

        Map<String, Class<?>> classMap = new HashMap<>();
        classMap.put("BaqsjRecordProperty", BaqsjRecordProperty.class);
        classMap.put("BaqsjRecordReport", BaqsjRecordReport.class);
        classMap.put("BaqsjRecordHandle", BaqsjRecordHandle.class);

        String busiKey = "BaqsjRecord" + eventNo;
        int eventID = BaqsjEventCOMMON.getEventID(eventNo);
        switch (eventID) {
            case BaqsjCOMMON.EVENT_ID_AccidentChokingFood: {
                UnsafeeventAccidentChokingFoodResponse response = new UnsafeeventAccidentChokingFoodResponse();
                UnsafeeventAccidentChokingFoodSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventAccidentChokingFoodSaveRequest.class);

                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordChokingFoodAccident());
                classMap.put(busiKey, BaqsjRecordAccidentChokingFood.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                result.setResStatus(ResStatus.STATUS_SUCCESS);
                result.setResMsg(ResStatus.STATUS_SUCCESS_MSG);
                break;
            }
            case BaqsjCOMMON.EVENT_ID_AccidentFall: {
                UnsafeeventAccidentFallResponse response = new UnsafeeventAccidentFallResponse();
                UnsafeeventAccidentFallSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventAccidentFallSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordAccidentFall());
                classMap.put(busiKey, BaqsjRecordAccidentFall.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_AccidentHurt: {
                UnsafeeventAccidentHurtResponse response = new UnsafeeventAccidentHurtResponse();
                UnsafeeventAccidentHurtSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventAccidentHurtSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordAccidentHurt());
                classMap.put(busiKey, BaqsjRecordAccidentHurt.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_AccidentOther: {
                UnsafeeventAccidentOtherResponse response = new UnsafeeventAccidentOtherResponse();
                UnsafeeventAccidentOtherSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventAccidentOtherSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordAccidentOther());
                classMap.put(busiKey, BaqsjRecordAccidentOther.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_AccidentOut: {
                UnsafeeventAccidentOutResponse response = new UnsafeeventAccidentOutResponse();
                UnsafeeventAccidentOutSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventAccidentOutSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordAccidentOut());
                classMap.put(busiKey, BaqsjRecordAccidentOut.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);
                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_AccidentSelfKill: {
                UnsafeeventAccidentSelfKillResponse response = new UnsafeeventAccidentSelfKillResponse();
                UnsafeeventAccidentSelfKillSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventAccidentSelfKillSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordAccidentSelfKill());
                classMap.put(busiKey, BaqsjRecordAccidentSelfKill.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_DiagnosisDietWrong: {
                Object response = processStandardEvent(dataRequest, requestPojo, eventClassListBoList, main, eventID, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_DiagnosisInfusionReaction: {
                Object response = processStandardEvent(dataRequest, requestPojo, eventClassListBoList, main, eventID, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));

                break;
            }
            case BaqsjCOMMON.EVENT_ID_DiagnosisMedicalHandle: {
                Object response = processStandardEvent(dataRequest, requestPojo, eventClassListBoList, main, eventID, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_DiagnosisOtherReaction: {
                Object response = processStandardEvent(dataRequest, requestPojo, eventClassListBoList, main, eventID, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_DiagnosisSampleWrong: {
                Object response = processStandardEvent(dataRequest, requestPojo, eventClassListBoList, main, eventID, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_DoctorAndPatientNegotiation: {
                UnsafeeventDoctorAndPatientNegotiationResponse response = new UnsafeeventDoctorAndPatientNegotiationResponse();
                UnsafeeventDoctorAndPatientNegotiationSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventDoctorAndPatientNegotiationSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordNegotiation());
                classMap.put(busiKey, BaqsjRecordNegotiation.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_HospitalInfected: {
                Object response = processStandardEvent(dataRequest, requestPojo, eventClassListBoList, main, eventID, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_MedicalBadReaction: {
                UnsafeeventMedicalBadReactionResponse response = new UnsafeeventMedicalBadReactionResponse();
                UnsafeeventMedicalBadReactionSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventMedicalBadReactionSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordUntowardeffect());
                classMap.put(busiKey, BaqsjRecordUntowardeffect.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);
                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_MedicalWrongDrug: {
                UnsafeeventMedicalWrongDrugResponse response = new UnsafeeventMedicalWrongDrugResponse();
                UnsafeeventMedicalWrongDrugSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventMedicalWrongDrugSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordWrongdrug());
                classMap.put(busiKey, BaqsjRecordWrongdrug.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_MedicalInstrument: {
                UnsafeeventMedicalInstrumentResponse response = new UnsafeeventMedicalInstrumentResponse();
                UnsafeeventMedicalInstrumentSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventMedicalInstrumentSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordMedicalinstrument());
                classMap.put(busiKey, BaqsjRecordMedicalinstrument.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_OtherReactionGeneral: {
                Object response = processStandardEvent(dataRequest, requestPojo, eventClassListBoList, main, eventID, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_OtherReactionPublic: {
                UnsafeeventOtherReactionPublicResponse response = new UnsafeeventOtherReactionPublicResponse();
                UnsafeeventOtherReactionPublicSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventOtherReactionPublicSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordOtherPublic());
                classMap.put(busiKey, BaqsjRecordOtherPublic.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_OtherReactionPublicSecurity: {
                UnsafeeventOtherReactionPublicSecurityResponse response = new UnsafeeventOtherReactionPublicSecurityResponse();
                UnsafeeventOtherReactionPublicSecuritySaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventOtherReactionPublicSecuritySaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordOtherPublicSecurity());
                classMap.put(busiKey, BaqsjRecordOtherPublicSecurity.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_PreventionAndProtection: {
                UnsafeeventPreventionAndProtectionResponse response = new UnsafeeventPreventionAndProtectionResponse();
                UnsafeeventPreventionAndProtectionSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventPreventionAndProtectionSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordProtection());
                classMap.put(busiKey, BaqsjRecordProtection.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_SurgicalBad: {
                UnsafeeventSurgicalBadResponse response = new UnsafeeventSurgicalBadResponse();
                UnsafeeventSurgicalBadSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventSurgicalBadSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordSurgicalBad());
                classMap.put(busiKey, BaqsjRecordSurgicalBad.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_SurgicalNonPlaned: {
                UnsafeeventSurgicalNonPlanedResponse response = new UnsafeeventSurgicalNonPlanedResponse();
                UnsafeeventSurgicalNonPlanedSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventSurgicalNonPlanedSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordNonPlaned());
                classMap.put(busiKey, BaqsjRecordNonPlaned.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_SurgicalOperationBad: {
                UnsafeeventSurgicalOperationBadResponse response = new UnsafeeventSurgicalOperationBadResponse();
                UnsafeeventSurgicalOperationBadSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventSurgicalOperationBadSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordOperationBad());
                classMap.put(busiKey, BaqsjRecordOperationBad.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_TransfusionBloodReaction: {
                UnsafeeventTransfusionBloodReactionResponse response = new UnsafeeventTransfusionBloodReactionResponse();
                UnsafeeventTransfusionBloodReactionSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventTransfusionBloodReactionSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordTransfusion());
                classMap.put(busiKey, BaqsjRecordTransfusion.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
            case BaqsjCOMMON.EVENT_ID_TransfusionWrongBlood: {
                UnsafeeventTransfusionWrongBloodResponse response = new UnsafeeventTransfusionWrongBloodResponse();
                UnsafeeventTransfusionWrongBloodSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventTransfusionWrongBloodSaveRequest.class);
                copyBaseProperty(main, response);

                dataParts.put(busiKey, data.getBaqsjRecordWrongblood());
                classMap.put(busiKey, BaqsjRecordWrongblood.class);

                processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }

            default: {
                Object response = processStandardEvent(dataRequest, requestPojo, eventClassListBoList, main, eventID, dataParts, classMap);
                result.setResData(page.setRecords(Arrays.asList(response)));
                break;
            }
        }

        result.setResStatus(ResStatus.STATUS_SUCCESS);
        result.setResMsg(ResStatus.STATUS_SUCCESS_MSG);

        return result;
    }

    /**
     * 拷贝基础数据
     *
     * @param main
     * @param response
     */
    private void copyBaseProperty(BaqsjRecordMain main, Object response) {
        SetGetUtil.setField(response, "id", main.getId());
        SetGetUtil.setField(response, "auditStatus", main.getAuditStatus());
        SetGetUtil.setField(response, "eventNo", main.getEventNo());
        SetGetUtil.setField(response, "eventName", main.getEventName());
    }

    /**
     * 处理标准数据请求
     *
     * @param dataRequest
     * @param requestPojo
     * @param eventClassListBoList
     * @param main
     * @param eventID
     */
    private Object processStandardEvent(Object dataRequest, RequestPojo requestPojo, List<EventClassListBo> eventClassListBoList, BaqsjRecordMain main, int eventID, Map<String, Object> dataParts, Map<String, Class<?>> classMap) {
        UnsafeeventStandardResponse response = new UnsafeeventStandardResponse();
        UnsafeeventStandardSaveRequest data = JSonUtil.toBean(JSonUtil.toJSONString(dataRequest), UnsafeeventStandardSaveRequest.class);
        response.setId(main.getId());
        response.setAuditStatus(main.getAuditStatus());
        response.setEventNo(main.getEventNo());
        response.setEventName(main.getEventName());

        processEventList(data.getId(), requestPojo, eventClassListBoList, eventID, response, data, dataParts, classMap);

        return response;
    }

    /**
     * 处理各类事件，写入对应表中
     *
     * @param requestPojo          系统对象
     * @param eventClassListBoList 事件列表属性
     * @param eventID              事件ID
     * @param response             响应数据对象
     * @param data                 请求数据
     * @param dataParts            请求分类对象
     * @param classMap             类对象
     */
    @Override
    public Object processEventList(Long sysId, RequestPojo requestPojo, List<EventClassListBo> eventClassListBoList, int eventID, Object response, Object data, Map<String, Object> dataParts, Map<String, Class<?>> classMap) {
        int insertOrUpdate;
        for (Map.Entry<String, Object> entry : dataParts.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            SetGetUtil.setField(value, "eventId", sysId);
            Object obj = SetGetUtil.getField(value, "id");
            insertOrUpdate = 0;
            if (Objects.nonNull(obj)) {
                insertOrUpdate = 1;
            }

            Object processedValue = process(eventClassListBoList, eventID, value, insertOrUpdate, requestPojo);
            try {
                if (Objects.nonNull(processedValue)) {
                    BeanUtils.copyProperties(processedValue, value);
                    SetGetUtil.setFieldByObject(response, key, value, classMap.get(key));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return null;
    }

    /**
     * 处理数据
     *
     * @param eventClassListBoList 事件对象
     * @param eventID              事件ID
     * @param data                 数据
     * @param operType             0-insert, 1-update, 2-delete, 其他-query
     * @return
     */
    @Override
    public Object process(List<EventClassListBo> eventClassListBoList, int eventID, Object data, int operType, RequestPojo requestPojo) {
        Object ret = null;

        if (Objects.isNull(eventClassListBoList) || Objects.isNull(data)) {
            return null; // 或者抛出异常，根据业务需求决定
        }

        EventClassListBo eventClassListBoProcess = eventClassListBoList.stream()
                .filter(bo -> bo.getEventid().equals(eventID))
                .findFirst()
                .orElse(null);

        if (Objects.isNull(eventClassListBoProcess)) {
            return null; // 或者抛出异常，根据业务需求决定
        }

        daoMap = new HashMap<>();
        daoMap.put(BaqsjRecordProperty.class, baqsjRecordPropertyDao);
        daoMap.put(BaqsjRecordReport.class, baqsjRecordReportDao);
        daoMap.put(BaqsjRecordHandle.class, baqsjRecordHandleDao);
        daoMap.put(BaqsjRecordAccident.class, baqsjRecordAccidentDao);
        daoMap.put(BaqsjRecordAccidentChokingFood.class, baqsjRecordAccidentDao);
        daoMap.put(BaqsjRecordAccidentFall.class, baqsjRecordAccidentDao);
        daoMap.put(BaqsjRecordAccidentHurt.class, baqsjRecordAccidentDao);
        daoMap.put(BaqsjRecordAccidentOther.class, baqsjRecordAccidentOtherDao);
        daoMap.put(BaqsjRecordAccidentOut.class, baqsjRecordAccidentDao);
        daoMap.put(BaqsjRecordNegotiation.class, baqsjRecordNegotiationDao);
        daoMap.put(BaqsjRecordUntowardeffect.class, baqsjRecordUntowardeffectDao);
        daoMap.put(BaqsjRecordWrongdrug.class, baqsjRecordWrongdrugDao);
        daoMap.put(BaqsjRecordMedicalinstrument.class, baqsjRecordMedicalinstrumentDao);
        daoMap.put(BaqsjRecordOtherPublic.class, baqsjRecordOtherDao);
        daoMap.put(BaqsjRecordOtherPublicSecurity.class, baqsjRecordOtherDao);
        daoMap.put(BaqsjRecordProtection.class, baqsjRecordProtectionDao);
        daoMap.put(BaqsjRecordSurgicalBad.class, baqsjRecordOperationDao);
        daoMap.put(BaqsjRecordNonPlaned.class, baqsjRecordOperationDao);
        daoMap.put(BaqsjRecordOperationBad.class, baqsjRecordOperationDao);
        daoMap.put(BaqsjRecordTransfusion.class, baqsjRecordTransfusionDao);
        daoMap.put(BaqsjRecordWrongblood.class, baqsjRecordWrongbloodDao);
        daoMap.put(BaqsjRecordInputblood.class, baqsjRecordInputbloodDao);

        String className = data.getClass().getName().substring(data.getClass().getName().lastIndexOf(".") + 1);

        Class<?> clazz = this.classMap.get(className);
        if (clazz != null) {
            Object dataEntity = JSonUtil.toBean(JSonUtil.toJSONString(data), clazz);
            Object dao = this.daoMap.get(clazz);
            if (dao instanceof BaseMapper) { // 所有 DAO 都继承自 BaseMapper
                if (operType == 0) {
                    SetGetUtil.setField(dataEntity, "id", 0L);
                    SetGetUtil.setField(dataEntity, "createBy", String.valueOf(requestPojo.getSysId()));
                    SetGetUtil.setField(dataEntity, "createTime", DateUtil.parseDate(DateUtil.formatDate(new Date(), DateUtil.DATE_TIME_FORMAT), DateUtil.DATE_TIME_FORMAT));
                    SetGetUtil.setField(dataEntity, "updateBy", String.valueOf(requestPojo.getSysId()));
                    SetGetUtil.setField(dataEntity, "updateTime", DateUtil.parseDate(DateUtil.formatDate(new Date(), DateUtil.DATE_TIME_FORMAT), DateUtil.DATE_TIME_FORMAT));
                    ((BaseMapper) dao).insert(dataEntity);
                    return dataEntity;
                } else if (operType == 1) {
                    SetGetUtil.setField(dataEntity, "updateBy", String.valueOf(requestPojo.getSysId()));
                    SetGetUtil.setField(dataEntity, "updateTime", DateUtil.parseDate(DateUtil.formatDate(new Date(), DateUtil.DATE_TIME_FORMAT), DateUtil.DATE_TIME_FORMAT));
                    ((BaseMapper) dao).updateById(dataEntity);
                    return dataEntity;
                } else if (operType == 2) {
                    Long sysId = (Long) SetGetUtil.getField(dataEntity, "id");
                    ret = ((BaseMapper) dao).deleteById(sysId);
                } else {
                    Long sysId = (Long) SetGetUtil.getField(dataEntity, "id");
                    Long eventId = (Long) SetGetUtil.getField(dataEntity, "eventId");
                    if (Objects.nonNull(sysId)) {
                        ret = ((BaseMapper) dao).selectById(sysId);
                    } else if (Objects.nonNull(eventId)) {
                        //通过event_id查询对应数据
                        try {
                            ret = SetGetUtil.invokeMethodHandle(dao.getClass(), dao, "queryByEventId", clazz, eventId);
                        } catch (Throwable ex) {
                            ex.printStackTrace();
                        }
//                        ret = dao.queryByEventId(eventId);
                    }
                }
            }
        }

        return ret; // 或者抛出异常，根据业务需求决定
    }

}
